﻿





using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.Diagnostics;

namespace Serialization.Script
{
    /// <summary>
    /// This class represents paths that enemy aircrafts will follow.
    /// </summary>
    public class Path
    {
        private List<Vector2> PathPoints
        {
            get;
            set;
        }

        private int index;

        /// <summary>
        /// Returns the next point of the path.
        /// </summary>
        /// <returns>A Vector2 pointing to the next point.</returns>
        public Vector2 getNextDestination()
        {
            Debug.Assert(PathPoints != null);
            Vector2 returnVector = Vector2.Zero;
            if (index < PathPoints.Count)
            {
                returnVector = PathPoints[index];
            }
            else if (index == PathPoints.Count && PathPoints.Count > 0)
            {
                returnVector = PathPoints[PathPoints.Count - 1];
            }
            index ++;
            return returnVector;
        }

        /// <summary>
        /// Returns if the path has finished.
        /// </summary>
        /// <returns>True if the path has finished, false otherwise.</returns>
        public bool isFinished()
        {
            Debug.Assert(PathPoints != null);
            return PathPoints.Count <= index;
        }

        /// <summary>
        /// Moves all points into a direction.
        /// </summary>
        /// <param name="direction">The direction to move into.</param>
        public void moveAllPoints(Vector2 direction)
        {
            Debug.Assert(PathPoints != null);
            Debug.Assert(PathPoints.Count > 0);
            for (int i = 0; i < PathPoints.Count; i++)
            {
                PathPoints[i] = Vector2.Add(PathPoints[i], direction);
            }
        }

        public void moveStartPoint(Vector2 point)
        {
            if (PathPoints != null)
            {
                if (PathPoints.Count > 0)
                {
                    PathPoints[0] = point;
                }
            }
        }

        public Path Clone()
        {
            List<Vector2> point = new List<Vector2>();
            point.InsertRange(0, PathPoints);
            return new Path(point);
        }

        public Path()
        {
            PathPoints = new List<Vector2>();
            index = 0;
        }

        public Path(List<Vector2> PathPoints)
        {
            this.PathPoints = PathPoints;
            index = 0;
        }
    }
}

